package com.so206.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * 978W短信接口
 */
public class SMSUtils {

    /**
     * 发送验证码短信
     */
    public static boolean send_code(String key, String phone, String moban, String app, String code) {
        try {
            String url = "http://api.978w.cn/yzmsms/index/appkey/" + key + "/phone/" + phone + "/moban/" + moban + "/app/" + app + "/code/" + code;
            String s = HttpClientUtils.get(url);
            JSONObject object = JSON.parseObject(s);
            System.out.println(s);
            String string = object.getString("status");
            if ("200".equals(string)) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 发送通知短信
     */
    public static boolean send_notify(String key, String phone, String context, String sign) {
        try {
            String url = "http://api.978w.cn/tzsms/index/appkey/" + key + "/phone/" + phone + "/content/" + context + "/sign/" + sign;
            String s = HttpClientUtils.get(url);
            JSONObject object = JSON.parseObject(s);
            System.out.println(s);
            String string = object.getString("status");
            if ("200".equals(string)) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

}
